package com.java.thread.demo.chapter1.suspend;

/**
 * Created by yiyongyao on 2017/12/19.
 *
 * suspend 暂停线程
 * resume  恢复线程
 *
 */
public class TestMain {


    public static void main(String[] args) {
        try {
            MyThread thread = new MyThread();
            thread.start();
            Thread.sleep(2000);
            //A 暂停
            thread.suspend();
            System.out.println("A = "+System.currentTimeMillis()+" i="+thread.getI());
            Thread.sleep(2000);
            System.out.println("A = "+System.currentTimeMillis()+" i="+thread.getI());
            //B 恢复
            thread.resume();
            Thread.sleep(2000);
            //C 暂停
            thread.suspend();
            System.out.println("B = "+System.currentTimeMillis()+" i="+thread.getI());
            Thread.sleep(2000);
            System.out.println("B = "+System.currentTimeMillis()+" i="+thread.getI());
             //D 停止
            thread.resume();
            thread.interrupt();
            System.out.println("线程是否已经停止: " + thread.isInterrupted());

        } catch (InterruptedException e) {
            e.printStackTrace();
        }


    }

}
